package com.cgy.service.Impl;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;

import com.cgy.entity.Keshi;
import com.cgy.repository.keshiRepository;
import com.cgy.service.keshiService;
@Service
public class keshiServiceImpl implements keshiService {
@Autowired 
private keshiRepository keshiRepository;

	@Override
	public Page<Keshi> findBynameKeshi(Keshi k, Pageable pageable) {
		
		return keshiRepository.findAll(get(k), pageable);
	}

	private Specification<Keshi> get(Keshi k) {
		// TODO Auto-generated method stub
		return new Specification<Keshi>() {

			@Override
			public Predicate toPredicate(Root<Keshi> root, CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder) {
				//创建动态sql
				Predicate predicate = criteriaBuilder.conjunction();
				List<Expression<Boolean>> exList = predicate.getExpressions();
				return predicate;
			}
			
		};
	}
	/**
	 *添加和修改科室的信息
	 */
	@Transactional
	@Override
	public Keshi addAndUpdateKeshi(Keshi k) {
		// TODO Auto-generated method stub
		return keshiRepository.saveAndFlush(k);
	}
@Transactional
	@Override
	public Integer deleteKeshi(Integer kid) {
		// TODO Auto-generated method stub
		return keshiRepository.deleteKeshi(kid);
	}

@Override
public List<Keshi> findAll() {
	// TODO Auto-generated method stub
	return keshiRepository.findAll();
}

}
